package org.alex.samples.model;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class MD5Utils {
	
	public static String GetMD5Code(String strObj){
      String resultString = null;
         try{
    	   resultString = new String(strObj);
    	   MessageDigest md = MessageDigest.getInstance("MD5");
    	   resultString = byteToString(md.digest(strObj.getBytes()));
          }catch(NoSuchAlgorithmException ex){
        	  ex.printStackTrace();
          }
         return resultString;
      }

	private static String byteToString(byte[] digest) {
		BASE64Encoder encoder=new BASE64Encoder();
		return encoder.encode(digest);
	}
	
	public static void  main(String[] args){
		String decodingPassword = MD5Utils.GetMD5Code("123456");
		System.out.println(decodingPassword);
	}
}
